﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using WcfServiceBomberman.Callbacks;
using WcfServiceBomberman.Contracts.Duplex;

namespace WcfServiceBomberman.Interfaces
{
    public class ServiceGameServer : Context.Handler ,IServiceGameServer
    {
        private GameServer server;
        
        public ServiceGameServer()
        {
            context.server = this;
            server = new GameServer();
        }

        public void register()
        {
            // get the callback from the server
            server.callback = OperationContext.Current.GetCallbackChannel<IServiceGameServerCallback>();
            server.adress = OperationContext.Current.Channel.RemoteAddress.Uri;
        }

        public void onGameCreated(GameCreatedArgs args)
        {
            // put in base
            // notify the website
            context.website.onGameCreated(server.adress, (int)args.port ,args.players);
        }

        public void onGameFinished(GameFinishedArgs args)
        {
            // put in base
            // notify the website
            context.website.onGameFinished(args);
        }

        public void createGame(Match match)
        {
            server.callback.newGame(match);
        }
    }
}
